package com.itheima.sh.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.sh.dto.HotelDto;
import com.itheima.sh.dto.Resp;
import com.itheima.sh.mapper.HotelMapper;
import com.itheima.sh.pojo.TbHotel;
import com.itheima.sh.service.HotelService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class HotelServicelmpl extends ServiceImpl<HotelMapper, TbHotel> implements HotelService {


    @Override
    public List<TbHotel> queryPageAndSize(Integer page, Integer size) {
        Page<TbHotel> objectPage = new Page<>(page, size);
        Page<TbHotel> hotelPage = this.page(objectPage);
        List<TbHotel> records = hotelPage.getRecords();
        return records;
    }

    @Override
    public Boolean deleteById(Integer id) {
        LambdaQueryWrapper<TbHotel> wrapper = Wrappers.<TbHotel>lambdaQuery().eq(TbHotel::getId, id);
        boolean b = remove(wrapper);
        return b;
    }

    @Override
    public Boolean updateHotel(HotelDto hotelDto) {
        String name = hotelDto.getName();
        LambdaQueryWrapper<TbHotel> wrapper = Wrappers.<TbHotel>lambdaQuery().eq(TbHotel::getName,name);
        return update(wrapper);
    }

    @Override
    public Boolean saveHotel(HotelDto hotelDto) {
        Long id = hotelDto.getId();
        LambdaQueryWrapper<TbHotel> wrapper = Wrappers.<TbHotel>lambdaQuery().eq(TbHotel::getId, id);
        TbHotel tbHotel = new TbHotel();
        BeanUtils.copyProperties(tbHotel,hotelDto);
        return save(tbHotel);
    }

}

